home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / ast / definitions.scm < prev    next >
Encoding:
Text File  |  1994-09-27  |  9.1 KB  |  233 lines  |  [TEXT/CCL2]

  1. ;;; File: ast/definitions.scm   Author: John
  2.  
  3. ;;; this file contains definitions for the named entities in the
  4. ;;; system.  These are used in both the front and back ends of the
  5. ;;; compiler.  These are created early in the compilation process
  6. ;;; (import/export) and filled in during compilation.  Binary interface
  7. ;;; files are just tables mapping names to definitions.
  8.  
  9. ;;; All definitions have these fields for managing name spaces.  All
  10. ;;; names are uniquified; this requires adding `;' to the front of data
  11. ;;; constructors to separate them from type constructors.  Module names
  12. ;;; do not have a `definition' data structure - the `module' structure
  13. ;;; serves the same purpose.
  14.  
  15. ;;; Definitions are found in two places: the symbol tables which are part of
  16. ;;; the module structure and the -ref nodes in the ast structure.  The -ref
  17. ;;; nodes have two fields: a name (from the parser) and a field which will
  18. ;;; point to the associated definition after name resolution.  Name resolution
  19. ;;; happens in a number of different places: top level definitions are
  20. ;;; resolved during import-export, type declarations are resolved during
  21. ;;; type declaration analysis, and everything else is resolved during scoping
  22. ;;; (alpha conversion).  The parser generates pre-resolved -ref nodes when
  23. ;;; parsing some constructs.  These refs denote pre-defined language
  24. ;;; constructs, such as lists, tuples, or prelude functions.
  25.  
  26. ;;; A special set of definitions constitutes the `core' of Haskell.  These
  27. ;;; definitions are pre-allocated and are filled in during the compilation
  28. ;;; of the Prelude.  This allows the bootstrap of the system.
  29.  
  30.  
  31. ;;; All defs require name, unit, and module args to make.
  32. ;;; Other slots should all have appropriate defaults.
  33.  
  34. (define-struct def
  35.   (slots
  36.    ;; the uniquified name (from the definition)
  37.    (name (type symbol))
  38.    ;; compilation unit defined in
  39.    (unit (type symbol))
  40.    ;; name of the defining module
  41.    (module (type symbol))
  42.    ;; used by the closure check
  43.    (exported? (type bool) (default '#f) (bit #t))
  44.    ;; for symbols in `core' Haskell; special case for IO
  45.    (core? (type bool) (default '#f) (bit #t))      
  46.    ;; Always a core sym.  Used to avoid putting in sym table
  47.    (prelude? (type bool) (default '#f) (bit #t))
  48.    ;; True when the def is created by an interface
  49.    (interface? (type bool) (default '#f) (bit #t))
  50.    ;; This is used by interface files.  Once the real definition of a symbol
  51.    ;; is available the interface file symbol is forwarded to the real thing.
  52.    (forward-to (type (maybe def)) (default '#f))
  53.    (where-defined (type (maybe source-pointer)) (default '#f))
  54.    ))
  55.  
  56. ;;; Variable information
  57.  
  58. (define-struct var
  59.   (include def)
  60.   (predicate var?)
  61.   (slots
  62.    ;; inferred during type inference
  63.    (type             (type (maybe ntype))     (default '#f))
  64.    ;; type affixed by sign-decl or class decl
  65.    (signature        (type (maybe ntype))     (default '#f))
  66.    ;; most variables have no fixity information.
  67.    (fixity           (type (maybe fixity))    (default '#f))
  68.    ;; The following attributes are used by the backend
  69.    (selector-fn?     (type bool)              (default '#f) (bit #t))
  70.    (force-strict?    (type bool)              (default '#f) (bit #t))
  71.    (inline?          (type bool)              (default '#f) (bit #t))
  72.    (always-inline?   (type bool)              (default '#f) (bit #t))
  73.    (toplevel?        (type bool)              (default '#f) (bit #t))
  74.    (simple?          (type bool)              (default '#f) (bit #t))
  75.    (strict?          (type bool)              (default '#f) (bit #t))
  76.    (optimized-refs?  (type bool)              (default '#f) (bit #t))
  77.    (standard-refs?   (type bool)              (default '#f) (bit #t))
  78.    (single-ref       (type (maybe int))       (default '#f))
  79.    (arity            (type int)               (default 0))
  80.    (referenced       (type int)               (default 0))
  81.    (value            (type (maybe flic-exp))  (default '#f))
  82.    (fullname         (type (maybe symbol))    (default '#f))
  83.    (inline-value     (type (maybe flic-exp))  (default '#f))
  84.    ;; Only function bindings use these slots
  85.    (strictness       (type (list bool))       (default '()))
  86.    (complexity       (type (maybe int))       (default '#f))
  87.    (optimized-entry  (type (maybe symbol))    (default '#f))
  88.    (annotations      (type (list annotation-value)) (default '()))
  89.    (fn-referenced    (type int)               (default 0))
  90.    (specializers     (type (list (tuple def t)))  (default '()))
  91.    (arg-invariant-value  (type (maybe flic-exp))  (default '#f))
  92.    (arg-invariant?   (type bool)              (default '#f) (bit #t))
  93.    ))
  94.   
  95.  
  96. ;;; This defines an individual class method
  97.  
  98. (define-struct method-var
  99.   (include var)
  100.   (predicate method-var?)
  101.   (slots
  102.    (class (type class) (uninitialized? #t))
  103.    (default (type (maybe var)) (uninitialized? #t))
  104.    (method-signature (type signature) (uninitialized? #t))))
  105.  
  106.  
  107. ;;; A data constructor
  108.  
  109. (define-struct con
  110.   (include def)
  111.   (predicate con?)
  112.   (slots
  113.    ;; These slots are initialized in the type declaration phase
  114.    (arity (type int) (uninitialized? #t))
  115.    (types (type (list type)) (uninitialized? #t))
  116.    (slot-strict? (type (list bool)) (default '()))
  117.    (tag (type int) (uninitialized? #t))
  118.    (alg (type algdata) (uninitialized? #t))
  119.    (infix? (type bool) (bit #t) (default '#f))
  120.    (signature (type ntype) (uninitialized? #t))
  121.    ;; Assigned during import-export phase
  122.    (fixity (type (maybe fixity)) (default '#f))
  123.    (lisp-fns (type t) (default '()))
  124.    ))
  125.  
  126.  
  127. ;;; Definitions used by the type system.
  128.  
  129. (define-struct tycon-def
  130.   (include def)
  131.   (slots
  132.    (arity (type integer) (default -1))))
  133.  
  134. (define-struct synonym
  135.   (include tycon-def)
  136.   (predicate synonym?)
  137.   (slots
  138.    ;; These slots are explicitly initialized in the type declaration phase.
  139.    (args (type (list symbol)) (uninitialized? #t))
  140.    (body (type type) (uninitialized? #t))  ; stored in ast form
  141.    ))
  142.  
  143. (define-struct algdata
  144.   (include tycon-def)
  145.   (predicate algdata?)
  146.   (slots
  147.    ;; These slots are initialized explicitly in the type declaration phase
  148.    ;; number of constructors
  149.    (n-constr (type int) (uninitialized? #t)) 
  150.    (constrs (type (list con)) (uninitialized? #t))
  151.    (context (type (list context)) (uninitialized? #t))
  152.    ;; arguments to tycon
  153.    (tyvars (type (list symbol)) (uninitialized? #t))
  154.    ;; signature for the type as a whole
  155.    (signature (type (maybe ntype)) (default '#f))
  156.    ;; classes this algdata is an instance of
  157.    (classes (type (list class)) (uninitialized? #t))
  158.    ;; true if all constructors have 0 arity
  159.    (enum? (type bool) (bit #t) (uninitialized? #t))
  160.    ;; true when only constructor
  161.    (tuple? (type bool) (bit #t) (uninitialized? #t))
  162.    ;; true for `tuple-syntax' tuples.
  163.    (real-tuple? (type bool) (bit #t) (uninitialized? #t))
  164.    ;; instances to derive
  165.    (deriving (type (list class)) (uninitialized? #t))
  166.    (export-to-lisp? (type bool) (default '#f) (bit #t))
  167.    (implemented-by-lisp? (type bool) (default '#f) (bit #t))
  168.    (skolem-type? (type bool) (default '#f) (bit #t))
  169.    (runtime-var (type var) (uninitialized? #t))
  170.    ))
  171.  
  172. (define-struct class
  173.   (include def)
  174.   (predicate class?)
  175.   (slots
  176.    ;; These slots are initialized in the import-export phase
  177.    (method-vars (type (list method-var)) (uninitialized? #t))
  178.    ;; These slots are explicitly initialized in the type declaration phase
  179.    ;; immediate superclasses
  180.    (super (type (list class)) (uninitialized? #t))
  181.    ;; all superclasses
  182.    (super* (type (list class)) (uninitialized? #t))
  183.    ;; name of class type variable
  184.    (tyvar (type symbol) (uninitialized? #t))
  185.    (instances (type (list instance)) (uninitialized? #t))
  186.    (kind (type (enum standard numeric other)) (uninitialized? #t))
  187.    (n-methods (type int) (uninitialized? #t))
  188.    (dict-size (type int) (uninitialized? #t))
  189.    (selectors (type (list (tuple method-var var))) (uninitialized? #t))
  190.    (runtime-var (type var) (uninitialized? #t))
  191.    ))
  192.  
  193. ;;; Since instances are not named there is no need to include def.  
  194.  
  195. (define-struct instance
  196.   (include ast-node)
  197.   (predicate instance?)
  198.   (slots
  199.    ;; These slots always have initializers supplied with MAKE.
  200.    (algdata (type algdata))
  201.    (tyvars (type (list symbol)))
  202.    (class (type class))
  203.    (context (type (list context)))
  204.    (gcontext (type (list (list class))))
  205.    (dictionary (type def))
  206.  
  207.    ;; Explicitly initialized during the type declaration phase.
  208.    (methods (type (list (tuple method-var var))) (uninitialized? #t))
  209.  
  210.    ;; These slots usually default on creation.
  211.    (decls (type (list decl)) (default '()))
  212.    ;; used during verification of derived instances
  213.    (ok? (type bool) (bit #t) (default #f))
  214.    ;; marks magically generated tuple instances
  215.    (special? (type bool) (bit #t) (default #f))
  216.    (skolem-inst? (type bool) (bit #t) (default #f))
  217.    ;; marks instances defined in interfaces.
  218.    (in-interface? (type bool) (bit #t) (default #f))
  219.    (runtime-var (type var) (uninitialized? #t))
  220.    ))
  221.  
  222. ;;; This is used for the deriving extension to Yale Haskell
  223.  
  224. (define-struct deriving
  225.   (include def)
  226.   (slots
  227.    (preconditions (type (list class)) (default '()))
  228.    (tyvar (type symbol) (uninitialized? #t))
  229.    (instances (type (list instance-decl)) (default '()))))
  230.  
  231.  
  232.  
  233.